/*
 * @lc app=leetcode.cn id=682 lang=javascript
 *
 * [682] 棒球比赛
 */

// @lc code=start
/**
 * @param {string[]} ops
 * @return {number}
 */
var calPoints = function (ops) {
  const stack = [];
  ops.map(item => {
    const top = stack.length - 1;
    switch (item) {
      case 'C':
        stack.pop();
        break;
      case 'D':
        stack.push(2 * stack[top]);
        break;
      case '+':
        stack.push(stack[top - 1] + stack[top]);
        break;

      default:
        // 这里别忘了把字符转成数字
        stack.push(+item);
        break;
    }
  });
  return stack.reduce((total, curVal) => total + curVal, 0);
};
// @lc code=end
